{% extends 'xadmin/base.html' %}
{% load staticfiles %}

{% block title %}
    站点管理
{% endblock %}

{% block css %}
    <link href="{% static 'xadmin/css/plugins/toastr/toastr.min.css' %}" rel="stylesheet">
{% endblock %}



{% block main %}
    <div class="row">
            <div class="col-lg-3 col-lg-offset-9">
                {% if request.user.is_superuser %}
                    <button type="button" class="btn btn-xs btn-primary" onclick="window.location.href='{% url 'siteadd' %}'">添加站点</button>
                {% else %}
                    {% for perm_type, perm_slug_list in perm_dic.items %}
                        {% if perm_type == 'site' %}
                            {% if 'add' in perm_slug_list %}
                                <button type="button" class="btn btn-xs btn-primary" onclick="window.location.href='{% url 'siteadd' %}'">添加站点</button>
                            {% endif %}
                        {% endif %}
                    {% endfor %}

                {% endif %}

            </div>
        </div>

    {% for site in sites %}
        <div class="forum-item">
            <div class="row">
                <div class="col-md-8">
                    <div class="forum-icon" style="margin-right:50px;padding-left:20px;">
                        <img src="/media/{{ site.logo }}" alt="" width="50" height="50">
                    </div>
                    <a href="javascript:;" style="margin-top: 5px;" class="forum-item-title">{{ site.name }}</a>
                    <div class="forum-sub-title">{{ site.domains }}</div>
                </div>
                <div class="col-md-4">
                    {% if request.user.is_superuser %}
                        <a href="{% url 'siteedit' site.id %}" style="margin-top: 5px;" class="btn btn-outline btn-primary">修改</a>
                        <button type="button" href="javascript:;" style="margin-top: 5px;" class="btn btn-outline btn-warning" onclick="delsite({{ site.id }})">删除</button>
                    {% else %}
                        {% for perm_type, perm_slug_list in perm_dic.items %}
                            {% if perm_type == 'site' %}
                                {% if 'update' in perm_slug_list %}
                                    <a href="{% url 'siteedit' site.id %}" style="margin-top: 5px;" class="btn btn-outline btn-primary">修改</a>
                                {% endif %}
                                {% if 'delete' in perm_slug_list %}
                                    <button type="button" href="javascript:;" style="margin-top: 5px;" class="btn btn-outline btn-warning" onclick="delsite({{ site.id }})">删除</button>
                                {% endif %}
                            {% endif %}
                        {% endfor %}

                    {% endif %}

                </div>
            </div>
        </div>
    {% endfor %}


{% endblock %}

{% block script %}
    <script src="{% static 'xadmin/js/plugins/toastr/toastr.min.js' %}"></script>
    <script src="{% static 'xadmin/js/myjs/toastr_customer.js' %}"></script>
    <script>
        function delsite(siteid){
            var url = '/admin/site/del/' + siteid + '/';
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: {'siteid': siteid, 'csrfmiddlewaretoken': '{{ csrf_token }}'},
                success: function(bk){
                    if(bk.status == '200'){
                        toastr.success(bk.message);
                        setTimeout(function() {
                          window.location.reload();
                        }, 3000)
                    }else{
                        toastr.error(bk.message);
                    }
                }
            })
        }
        toastr.options = {
          "closeButton": true,
          "debug": false,
          "progressBar": true,
          "positionClass": "toast-top-center",
          "onclick": null,
          "showDuration": "400",
          "hideDuration": "1000",
          "timeOut": "3000",
          "extendedTimeOut": "1000",
          "showEasing": "swing",
          "hideEasing": "linear",
          "showMethod": "fadeIn",
          "hideMethod": "fadeOut"
        }
    </script>

{% endblock %}